package com.wu.foodsafetyplayer.app.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.dueeeke.videoplayer.ijk.IjkPlayerFactory;
import com.dueeeke.videoplayer.player.VideoView;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.wu.foodsafetyplayer.R;
import com.wu.foodsafetyplayer.app.bean.AppVideoBackBean;

/**
 * GridView适配器
 *
 * @author zihao
 */
public class AppVideoAdapter extends BaseAdapter {
    private static final String TAG = AppVideoAdapter.class.getSimpleName();
    private LayoutInflater inflater;
    private String[] itemNames = new String[]{"24小时内", "前1-2天", "前2-3天", "前3-4天", "前4-5天", "前5-6天", "前6-7天"};
    private Context context;
    private AppVideoBackBean appVideoBackBean;

    public AppVideoAdapter(Context context, AppVideoBackBean appVideoBackBean) {
        inflater = LayoutInflater.from(context);
        this.context = context;
        this.appVideoBackBean = appVideoBackBean;
    }

    @Override
    public int getCount() {
        if (appVideoBackBean == null) {
            return itemNames.length;
        } else {
            return appVideoBackBean.data.size();
        }
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        if (appVideoBackBean == null) {
            return itemNames[position];
        } else {
            return appVideoBackBean.data.get(position);
        }
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        ViewHolder holder;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.item_app_video_view, null);
            holder = new ViewHolder();
            holder.itemName = convertView.findViewById(R.id.item_app_video_name);
            holder.videoImg = convertView.findViewById(R.id.item_app_video_img);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        if (appVideoBackBean == null) {
            holder.itemName.setText(itemNames[position]);
        } else {
            holder.itemName.setText("开始：" + appVideoBackBean.data.get(position).start + "\n时间：" + appVideoBackBean.data.get(position).stop);
        }
        ImageLoader.getInstance().displayImage("https://i03piccdn.sogoucdn.com/9117295b45f41103", holder.videoImg);
        return convertView;
    }

    /**
     * 工具类
     */
    private class ViewHolder {
        TextView itemName;
        ImageView videoImg;
    }

}
